<?php
/**
 * Core_Personal_ProfileForm
 * 
 * @author naspeh
 * @version $Id: ProfileForm.php 670 2008-06-30 10:24:28Z naspeh $
 */
class Core_Personal_ProfileForm extends Core_Form 
{
    /**
     * Инициализация
     *
     * @return Core_Personal_ProfileForm
     */    
    public function init()
    {
        $this->addElement('text', 'fullname', array(
            'required' => true,
            'label'    => 'Полное имя:',
            'attribs'  => array(
                'class' => 'text span-4',
                'size'  => 32
            ),     
            'validators' => array(
                new Zend_Validate_StringLength(3,32),
                new Zend_Validate_Alnum(true),            
            )
        ));
        $this->addElement('button', 'submit', array(
            'type'     => 'submit',
            'label'    => 'Сохранить',
            'attribs'  => array(
                'class' => 'positive',
                'icon'  => 'tick'
            )
        ));
        $defaults = array(
            'fullname' => Core_Auth::get('fullname')
        );
        $this->setDefaults($defaults);        
        return $this;
    }
    /**
     * Запускает форму на выполнение
     *
     * @return Core_Personal_ProfileForm
     */    
    public function process()
    {
        $rolesTable = new Core_Table_Roles();
        $values = $this->getValues(true);
        $data = array(
            'fullname' => $values['fullname']
        );
        $rolesTable->update($data, 'id = ' . Core_Auth::get('id'));
        Core_Auth::init();
        Core_Message::add('Данные сохранены.');
        return $this;        
    }
}
